<?php defined("MAIN_DIR") or die("No direct access");

$error = array();
if (isset($_POST['action']) && $_POST['action'] == "add")
{
	$path = trim(preg_replace("/'/","",$_POST['path']));
	$path = preg_replace("/\"/","",$path);
	$power = $_POST['power'];
	$city_name = trim(filter_var($_POST['city_name'],FILTER_SANITIZE_MAGIC_QUOTES));
	$city_name_rod = trim(filter_var($_POST['city_name_rod'],FILTER_SANITIZE_MAGIC_QUOTES));
	$city_name_pred = trim(filter_var($_POST['city_name_pred'],FILTER_SANITIZE_MAGIC_QUOTES));
	
	echo $add_query = "insert into `city` (`path`,`power`,`city_name`,`city_name_rod`,`city_name_pred`) values ('$path','$power','$city_name','$city_name_rod','$city_name_pred')";
	if (mysql_query($add_query)) {
		to("/admin/site/cities/");
	} else {
		$error['query'] = "Не удалось добавить";
	}
}

require_once ADMIN.HEADFILE;
?>
<div align="left">
<h1>Добавление города</h1>
<hr /><?php
if (count($error) > 0)
	echo "<p style='color:red'>".implode("<br />",$error)."</p>";
?><form method='POST'>
<input type='hidden' name='action' value='add' />
<table cellpadding='5' cellspacing='0'>
	<tr>
		<td width="200px">Название города</td>
		<td width="300px">
			<input style='width:100%' type='text' name='city_name' value='<?php if (isset($_POST['city_name'])) echo $_POST['city_name'];?>' />
		</td>
	</tr>
	<tr>
		<td>Путь</td>
		<td><input style='width:100%' type='text' name='path' value='<?php if (isset($_POST['path'])) echo $_POST['path'];?>' /></td>
	</tr>
	<tr>
		<td>Включен</td>
		<td>
			<input type='radio' name='power' value='on' <?php if ($route->POST('power') != "off") echo "checked='checked'"; ?> /> Да
			<input type='radio' name='power' value='off' <?php if ($route->POST('power') == "off") echo "checked='checked'"; ?> /> Нет
		</td>
	</tr>
	<tr>
		<td>Название в род. падеже</td>
		<td><input style='width:100%' type='text' name='city_name_rod' value='<?php if (isset($_POST['city_name_rod'])) echo $_POST['city_name_rod'];?>' /></td>
	</tr>
	<tr>
		<td>Название в пред. падеже</td>
		<td><input style='width:100%' type='text' name='city_name_pred' value='<?php if (isset($_POST['city_name_pred'])) echo $_POST['city_name_pred'];?>' /></td>
	</tr>
	<tr valign='top'>
		<td colspan='2' align="right"><button style="width:100px;height:30px" type="submit">Добавить</button></td>
	</tr>
</table>
</form>
<br /><hr /><br />
</div>

<?php require_once ADMIN.FOOTERFILE; ?>